package com.andy.eqm.server.socket;
import com.andy.eqm.server.socket.codec.RequestDecoder;
import com.andy.eqm.server.socket.codec.ResponseEncoder;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

public class GameServerInitializer extends ChannelInitializer<Channel>{
	
	@Override
	protected void initChannel(Channel ch) throws Exception {
		if(!GameServer.isOk()) ch.close();
		ChannelPipeline pipeline = ch.pipeline();
		//处理心跳
//		pipeline.addLast(new IdleStateHandler(0, 0, 1800, TimeUnit.SECONDS));
//		pipeline.addLast(new HeartbeatHandler());
		
		// 4(len)+body()
		pipeline.addLast(new LengthFieldBasedFrameDecoder(1024,0,4,0,4));
		pipeline.addLast("UserDecoder", new RequestDecoder());
		pipeline.addLast("UserEncoder", new ResponseEncoder());
		pipeline.addLast(new SocketFrameHandler(false));
	}
}